Skip to content

Exclude comment sections from workspace symbols by default #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 22, 2025

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Jul 7, 2025

Branched from #865.
Addresses posit-dev/positron#4886.

When a comment section like # name --- clashes with an actual symbol like name <- function() {}, whichever symbols comes first (usually the section) is included in the workspace index, and the other is ignored. Ideally we'd track both but for now we only track one identifier per file.

This causes sections to win over function definitions in cases like this:

# my_section ----

my_section <- function() {}

my_section # Reference

If you then jump to definition on a reference to that function, Positron jumps to the section instead of the function.

  • To fix this, we now allow functions and variables to overwrite sections in the indexer.

  • In addition, we no longer emit sections as workspace symbols by default. This can be turned back on with a new setting positron.r.workspaceSymbols.includeCommentSections. This is consistent with the fix in Exclude section headers from workspace symbols in R packages quarto-dev/quarto#755 where we no longer export markdown headers as workspace symbols by default, to avoid flooding workspace symbol quickpicks (# prefix in command palette) with section headers.

QA Notes

  • You should be able to command+quick on the my_section reference and be taken to the function definition rather than the section. This should be the case no matter the value of positron.r.workspaceSymbols.includeCommentSections.

  • When positron.r.workspaceSymbols.includeCommentSections is set to true, you should see comment sections in the workspace symbol quickpick. Otherwise they shouldn't be included.

Copy link
Contributor

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, mostly just want some test coverage since this is a bit tricky

@lionel- lionel- force-pushed the task/refactor-config branch 4 times, most recently from 1c4fa66 to a4d669b Compare July 22, 2025 10:07
@lionel- lionel- force-pushed the feature/optional-section-workspace-symbols branch from 120984c to ee55fe4 Compare July 22, 2025 12:52
@lionel-
Copy link
Contributor Author

lionel- commented Jul 22, 2025

We've now got the requested test coverage and a test-only RAII indexer guard to help clean up the index after tests have run.

@lionel- lionel- force-pushed the task/refactor-config branch from a4d669b to eccee92 Compare July 22, 2025 14:59
Base automatically changed from task/refactor-config to main July 22, 2025 14:59
@lionel- lionel- force-pushed the feature/optional-section-workspace-symbols branch from eb5b2aa to 0eb735e Compare July 22, 2025 15:00
@lionel- lionel- force-pushed the feature/optional-section-workspace-symbols branch from eebe91d to ce75104 Compare July 22, 2025 15:35
`lsp_types::Url::from_file_path()` returns `None` if not a valid path.
Path should start with e.g. `C:\` on Windows.
@lionel- lionel- force-pushed the feature/optional-section-workspace-symbols branch from ce75104 to 40e9c0f Compare July 22, 2025 15:46
@lionel- lionel- merged commit 3d8c23a into main Jul 22, 2025
6 checks passed
@lionel- lionel- deleted the feature/optional-section-workspace-symbols branch July 22, 2025 16:01
@github-actions github-actions bot locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants